﻿using System;
using System.IO;

namespace QSearcher.QCrawler.QP8848Analyzer
{
    public class Analyzer : IAnalyzer
    {
        public override string Name { get { return "拍吧"; } }

        public override string Remark { get { return "http://www.p8848.com/"; } }

        public override IAnalyzer.AnalyzeResult Analyze(IAnalyzer.AnalyzeSource source)
        {
            var file = source.File;
            this.PrintLog("开始读取网页文件{" + file + "}.......");
            var html = File.ReadAllText(file);
            this.PrintLog("读取网页文件{" + file + "}完成.");
            var hrefs = this.GetHrefs(html);
            var imgs = this.GetImgs(html);

            hrefs.RemoveAll(p => { return p.IndexOf("http://www.p8848.com") != 0; });
            imgs.RemoveAll(p => { return p.IndexOf("http://res.p8848.com/") != 0; });
            
            var res = new IAnalyzer.AnalyzeResult();
            res.ID = source.ID;
            res.Msg = "";
            res.RequestUrls = hrefs;
            res.DownloadUrls = imgs;
            return res;
        }
    }
}
